<template>
  <div>
  <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</el-button>
      </template>
    </FilterTable>

    <BaseDialog
      width="400px"
      :visible.sync="openAddParamPopup"
      :title="title"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '0px'}"
    >
      <actionParam :row="row" :actionType="actionType" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
  import { getgraphicAndAssemblyInfoPage,getGraphicModelList,getGraphicSystemList,getList,enableDisable} from '@/api/partsmanage/trafficParams/categoryRepair/index';
  import { dictionary } from '@/utils/dictMixin';
  import actionParam from './customPopup/actionParam';

  export default {
    name: "partParameter",
    mixins: [dictionary],
    components: {actionParam},
    data() {
      return {
        topFilterList: this.createFormList(),
        fetchParams: {xhrAbort: true},
        columns: this.createTableColumns(),
        fetchApi: getList,
        openAddParamPopup: false,
        title:"",
        actionType:"",
        row:{}

      };
    },
    methods: {
      closeHandler(){
      this.openAddParamPopup = false;
      //刷新页面
      this.fetchParams = Object.assign({}, this.fetchParams);

      },
      edit(row){
      this.openAddParamPopup = true;
      this.title = "备件类别编辑";
      this.actionType = "edit";
      this.row = row;
      },
      add(){
      this.openAddParamPopup = true;
      this.title = "备件类别新增";
      this.actionType = "add";
      this.row = null;
      },
      collapseHandle() {
        this.$nextTick(() => {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },
      changeHandle(val) {
        this.fetchParams = Object.assign({}, val);
      },
      createTableColumns () {
        return[
          {
              title: '序号',
              dataIndex: 'index',
              width: 70,
              sorter: true,
              align:"center",
              render: props => {
                return <span>{props.row.index + 1}</span>;
              }
          },
          {
            title: '操作',
            dataIndex: 'column-action',
            width: 100,
            align:"center",
            render: (props, h) => {
              return (
                <div>
                  <el-button size="mini" type="text" onClick={() => this.edit(props.row)}>
                    编辑
                  </el-button>
                </div>
              );
            }
          },
          {
            title: '备件类别',
            dataIndex: 'partTypeName',
            sorter: true,
            width: 400,
            align:"center"
          }
          // {
          //   title: '退货折扣率(%)',
          //   dataIndex: 'discountRate',
          //   sorter: true,
          //   align:"center",
          //   editable: true,
          //   defaultEditable: true,
          //   editRequired: true,
          //   editType: 'number',
          //   editValidator:(rule, value, callback) => {
          //     var discountRate = parseInt(value.discountRate);
          //     if (discountRate === undefined || discountRate === '' || discountRate === null) {
          //       callback(new Error('值不能为空'));
          //     }
          //     var pattern = /^[+]{0,1}(\d+)$/;
          //     if (pattern.test(value.discountRate)) {

          //     }else{
          //       callback(new Error('请输入正整数'));
          //       return;
          //     }



          //     if (discountRate === undefined || discountRate === '' || discountRate === null) {
          //       callback(new Error('值不能为空'));
          //     }
          //     var g = /^\-?[0-9]\d*.?\d*$/;
          //     if (g.test(discountRate)) {
          //       if (100 >= discountRate > 0) {
          //         callback();
          //         editPartReturnParam(value).then(res =>{
          //           this.$notify.success({title: '提示信息',message:'修改成功!'});
          //           this.fetchParams = Object.assign({}, this.fetchParams);
          //         }).catch(err =>{
          //           this.$notify.error({title: '提示信息',message:err.errMsg||'修改失败!'});
          //         })
          //         return;
          //       }
          //     }
          //     callback(new Error('只能输入数字，且在0-100之间'));
          //   },
          // }
        ]
      },
      createFormList() {
        return [
          {
            type: 'INPUT',
            label: '备件类别',
            fieldName: 'partTypeName',
            placeholder: '请输入...'
          },
        ]
      },
    },

  }
</script>

<style scoped>

</style>
